package com.song.cloud.sentinel.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.swing.text.html.HTMLDocument;
import java.util.concurrent.TimeUnit;

/**
 * @Author ZhangGuisong
 * @Date 2021/2/27-20:53
 */
@RestController
@Slf4j
public class sentinelController {
    @GetMapping("/sentinel/testA")
    public String testA(){

        String name = Thread.currentThread().getName();
        log.info("this is a test thread"+name);
        return "----testA";
    }
    @GetMapping("/sentinel/testB")
    public String testB(){
        return "----testB";
    }

    @GetMapping("/sentinel/testD")
    public String testD(){

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "----testD RT 测试";
    }
    @GetMapping("/sentinel/testE")
    public String testE(){
        int num=10/0;
        log.info("test 异常比例");
        return "----testE";
    }
     /*热点规则*/
     @GetMapping("/sentinel/testHotKey")
     @SentinelResource(value="testHotKey",blockHandler ="deal_hotKey")
     public String testHotkey(@RequestParam(value = "a1",required = false) String a1, @RequestParam(value="a2",required = false) String a2){
         return "this is HOtkey test";
     }
     public String deal_hotKey(String a1,String a2,BlockException blockException){
         return "this is deal_HOTKEY METHOD";
     }
}
